using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using AgilePlannerDT.Persister;

namespace AgilePlannerDT.Data.Impl
{
    public class IndexCardWithChildDataObject : IndexCardDataObject, IndexCardWithChild
    {
        #region Constants

        public static readonly string START_DATE_PROPERTY = "StartDate";
        public static readonly string AVAILABLE_EFFORT_PROPERTY = "AvailableEffort";
        public static readonly string END_DATE_PROPERTY = "EndDate";
        public static readonly string REMAINING_EFFORT_PROPERTY = "RemainingEffort";

        #endregion

        #region Attributes

        protected DateTime startdate, enddate;

        Project project;

        public Project Project
        {
            get;
            set;
        }

        protected float availableEffort;

        protected List<StoryCard> storycards = new List<StoryCard>();

        #endregion

        #region IndexCardWithChild Members

        public void AddStoryCard(StoryCard storycard)
        {
            if (!this.storycards.Contains(storycard))
            {
                storycard.Parent = this.ID;
                this.storycards.Add(storycard);
                storycard.ParentCard = this;
            }
            else
            {
            //    throw new ForbiddenOperationException("Cannot add storycard with ID "+ storycard.ID +"! Storycard already exists.");
            }
        }

        public List<StoryCard> StoryCardChildren
        {
            get { return this.storycards; }
            set { this.storycards = value; }
        }

        public void RemoveStoryCard(StoryCard storycard)
        {
            this.storycards.Remove(storycard);
        }

        public DateTime StartDate
        {
            get { return this.startdate; }
            set { 
                if(this.startdate == value)
                {
                    return;
                }
                object before = Clone();
                this.startdate = value;
                object after = Clone();
                Notify(START_DATE_PROPERTY, before, after);
                //Notify(START_DATE_PROPERTY);
            }
        }

        public float AvailableEffort
        {
            get { return this.availableEffort; }
            set { 
                if(this.availableEffort == value)
                {
                    return;
                }
                object before = Clone();
                this.availableEffort = value;
                object after = Clone();
                Notify(AVAILABLE_EFFORT_PROPERTY, before, after);
                //Notify(AVAILABLE_EFFORT_PROPERTY);
            }
        }

        public DateTime EndDate
        {
            get { return this.enddate; }
            set
            {
                if (this.enddate == value)
                {
                    return;
                }
                object before = Clone();
                this.enddate = value;
                object after = Clone();
                Notify(END_DATE_PROPERTY, before, after);
                //Notify(END_DATE_PROPERTY);
            }
        }

        #endregion

    }
}